package com.itheima.demo;

import com.itheima.domain.Student;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

/**
 * @author Zhang_Han
 * @version 1.0
 * @date 2020/7/17 15:59
 */
@SuppressWarnings("all")
public class Demo_006 {
    public static void main(String[] args) throws Exception {

        //获取字节码对象 ;
        Class clazz = Student.class;

        //获取构造方法;
        Constructor constructor = clazz.getConstructor();

        //根据构造方法创建对象;
        Object o = constructor.newInstance();

        //获取成员变量 ;
        Field field = clazz.getField("age");

        //修改变量的值  ;
        field.set(o, 88);

        //获取修改之后的值;
        Object age = field.get(o);

        //打印对应的值;
        System.out.println(age);
    }
}
